﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Portal.GUI.Users.Common;
using Xmobile.Users;
//using Portal.Core.DAL;
using System.ComponentModel;
using Portal.BO.Editoral.Category;
using Portal.User.Security;
using Portal.BO.Editoral.Statistic;
using Portal.BO.Editoral.Newsedit;
using Portal.BO.Editoral.CommentManagement;


namespace Portal.GUI.Administrator.BoxManagement.Business
{
    public class Box
    {
        public static Boolean CheckBox(string box)
        {
            //nếu trùng trả về true, ko trả về false
            //if box.ToString()= "fd";
            //{
            //    return true;
            //}
            //else
            //{
                return false;
            //}
        }

        public static Boolean Insert(string Box_Name) 
        {
            int __td;
            //using (Cafef_DAL.MainDB db = new Cafef_DAL.MainDB())
            using (MainDB db = new MainDB())
            {
                __td = db.StoreProcedure.Box_Insert(Box_Name);
            }
            //return __td;
            return true;
        }
        /////
        public static DataTable GetBoxlist(string strWhere)
        {
            DataTable objresult;
           using (MainDB objdb = new MainDB())
            {
                
                    //objresult = objdb.NewsCollection.GetPageAsDataTable(intPageNum, PageSize, strWhere, "News_ModifiedDate DESC"); ;
                    objresult = objdb.StoreProcedure.News_GetListBox(strWhere);
                
            }
            return objresult;
        }
        public static DataTable GetPermisslist(string BoxID)
        {
            DataTable objresult;
            int Box_ID = Convert.ToInt32(BoxID.ToString());
            using (MainDB objdb = new MainDB())
            {

                //objresult = objdb.NewsCollection.GetPageAsDataTable(intPageNum, PageSize, strWhere, "News_ModifiedDate DESC"); ;
                objresult = objdb.StoreProcedure.News_GetPermisslist(Box_ID);

            }
            return objresult;
        }
        //Lấy danh sách gán quyền cho box 
        public static DataTable GetPerBoxlist(string strWhere)
        {
            DataTable objresult;
            using (MainDB objdb = new MainDB())
            {

                //objresult = objdb.NewsCollection.GetPageAsDataTable(intPageNum, PageSize, strWhere, "News_ModifiedDate DESC"); ;
                objresult = objdb.StoreProcedure.News_GetListPerBox(strWhere);

            }
            return objresult;
        }
        public static DataTable GetPermiss(int BoxID)
        {
            DataTable objresult;
            using (MainDB objdb = new MainDB())
            {
                objresult = objdb.StoreProcedure.News_GetPermiss(BoxID);
            }
                return objresult;
        }
        public static DataTable GetBoxUser(string strUser)
        {
            DataTable objresult;
            using (MainDB objdb = new MainDB())
            {
                objresult = objdb.StoreProcedure.News_GetBoxUser(strUser);
            }
            return objresult;
        }
        public static DataTable getPage(int numPage)
        {
            int intPagenum = numPage;
            DataTable objTb = new DataTable();
            objTb.Columns.Add(new DataColumn("Text", typeof(string)));
            objTb.Columns.Add(new DataColumn("Value", typeof(string)));
            for (int i = 1; i <= intPagenum; i++)
            {
                DataRow myRow = objTb.NewRow();
                myRow["Text"] = i.ToString();
                myRow["Value"] = Convert.ToString(i - 1);
                objTb.Rows.Add(myRow);
            }
            if (intPagenum == 0)
            {
                DataRow myRow = objTb.NewRow();
                myRow["Text"] = "1";
                myRow["Value"] = "0";
                objTb.Rows.Add(myRow);
            }
            return objTb;
        }
        public static string selectBox(int Box_ID)
        {
            string __td;
            using (MainDB db = new MainDB())
            {
                __td = db.StoreProcedure.Box_Select(Box_ID);
            }
            return __td;
        }
        public static Boolean UpdateBox(int Box_ID,string Box_Name)
        {
            int __td;
            using (MainDB db = new MainDB())
            {
                __td = db.StoreProcedure.Box_Update(Box_ID,Box_Name);
            }
            //return __td;
            return true;
        }
        public static Boolean DeleteBox(int BoxID)
        {
            int __td;
            using (MainDB db = new MainDB())
            {
                __td = db.StoreProcedure.Box_Delete(BoxID);
            }
            //return __td;
            return true;
        }
        public static Boolean DeleteBoxPermission(int BoxPer)
        {
            int __td;
            using (MainDB db = new MainDB())
            {
                __td = db.StoreProcedure.BoxPer_Delete(BoxPer);
            }
            //return __td;
            return true;
        }
        public static Boolean DeletePerBox(int BP_ID)
        {
            int __td;
            using (MainDB db = new MainDB())
            {
                __td = db.StoreProcedure.PerBox_Delete(BP_ID);
            }
            return true;
        }
        public static Boolean UpdateBoxIndex(int BoxID, int BoxIndex)
        {
            int __td;
            using (MainDB db = new MainDB())
            {
                __td = db.StoreProcedure.Box_UpdateIndex(BoxID, BoxIndex);
            }
            return true;
        }
        public static Boolean UpdatePerBoxIndex(int BP_ID, int Index)
        {
            int __td;
            using (MainDB db = new MainDB())
            {
                __td = db.StoreProcedure.PerBox_UpdateIndex(BP_ID, Index);
            }
            return true;
        }
        public static Boolean InsertBox_Per(int Box, int Per, int Index, string url, string Control, int Iscount, int Isprefix,int Channel)
        {
            int __td;
            using (MainDB db = new MainDB())
            {
                __td = db.StoreProcedure.BoxPer_Insert(Box,Per,Index,url,Control,Iscount,Isprefix,Channel);
            }
            return true;
        }
        public static Boolean CheckPermiss(int Box, int Per)
        {
            int __td;
            using (MainDB db = new MainDB())
            {
                __td = db.StoreProcedure.CheckPermiss(Box, Per);
            }
            if (__td == 0)
            {
                return true;
            }
            else
            {
                return false;
            }
            //return __td;
        }
        public static Boolean CheckBoxUser(string strUser, int Box_ID)
        {
            int __td;
            using (MainDB db = new MainDB())
            {
                __td = db.StoreProcedure.CheckBox_User(strUser, Box_ID);
            }
            if (__td == 0)
            {
                return true;
            }
            else
            {
                return false;
            }
            //return __td;
        }
        public static Boolean InsertPermis(int Box, int Per, int boxIndex,string Url, string Control)
        {
            int __td;
            using (MainDB db = new MainDB())
            {
                __td = db.StoreProcedure.Permiss_Insert(Box, Per, boxIndex,Url,Control);
            }
            return true;
        }
        public static Boolean InsertBoxUser(string strUser, int Box_ID)
        {
            int __td;
            using (MainDB db = new MainDB())
            {
                __td = db.StoreProcedure.BoxUser_Insert(strUser, Box_ID);
            }
            return true;
        }
        public static Boolean UpdateBox_Per(int BP_ID,int Box, int Per, int Index, string url, string Control, int Iscount, int Isprefix, int Channel)
        {
            int __td;
            using (MainDB db = new MainDB())
            {
                __td = db.StoreProcedure.BoxPer_Update(BP_ID,Box, Per, Index, url, Control, Iscount, Isprefix, Channel);
            }
            return true;
        }
        public static DataRow GetDataRow(int BP_ID)
        {
            DataRow __td;
            using (MainDB db = new MainDB())
            {
                __td = db.StoreProcedure.BoxPer_GetDataRow(BP_ID);
            }
            return __td;
        }
    }
}
